package st.business.tepth.business.user.busnumber;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.bean.BusNumberBean;
import st.business.tepth.view.CommonPagerIndicator;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

/**
 * @author zhangyu
 * @date 2019/3/5
 */
public class NumberNavigatorAdapter extends CommonNavigatorAdapter {
    private int fontGray;
    private int fontYellow;
    private int fontGreen;
    private Drawable drawableGray;
    private Drawable drawableYellow;
    private Drawable drawableGreen;
    private List<BusNumberBean> mBusNumberBeans;
    private ViewPager mViewPager;
    private Context mContext;

    public NumberNavigatorAdapter(Context context,
                                  ViewPager viewPager,
                                  List<BusNumberBean> list) {
        mBusNumberBeans = list;
        mViewPager = viewPager;
        mContext = context;
        drawableGray = context.getResources().
                getDrawable(R.drawable.shape_circle_gray);
        fontGray = context.getResources().getColor(R.color.fontColorGray);
        drawableGray.setBounds(0, 0, drawableGray.getMinimumWidth(), drawableGray.getMinimumHeight());
        drawableYellow = context.getResources().
                getDrawable(R.drawable.shape_circle_yellow);
        fontYellow = context.getResources().getColor(R.color.fontColorYellow);
        drawableYellow.setBounds(0, 0, drawableYellow.getMinimumWidth(), drawableYellow.getMinimumHeight());
        drawableGreen = context.getResources().
                getDrawable(R.drawable.shape_circle_green);
        fontGreen = context.getResources().getColor(R.color.fontColorGreen);
        drawableGreen.setBounds(0, 0, drawableGreen.getMinimumWidth(), drawableGreen.getMinimumHeight());
    }

    @Override
    public int getCount() {
        return mBusNumberBeans.size();
    }

    @Override
    public IPagerTitleView getTitleView(Context context, final int index) {

        BusNumberBean busNumberBean = mBusNumberBeans.get(index);
        SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context);
        simplePagerTitleView.setText(busNumberBean.getVehicle_no());
        int state = busNumberBean.getJob_process_status();
        if (state == 1) {
            simplePagerTitleView.setTextColor(fontGray);
            simplePagerTitleView.setCompoundDrawables(null, drawableGray, null, null);
        } else if (state == 2) {
            simplePagerTitleView.setTextColor(fontYellow);
            simplePagerTitleView.setCompoundDrawables(null, drawableYellow, null, null);
        } else {
            simplePagerTitleView.setTextColor(fontGreen);
            simplePagerTitleView.setCompoundDrawables(null, drawableGreen, null, null);
        }
        simplePagerTitleView.setTextSize(15);
        simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mViewPager.setCurrentItem(index);
            }
        });
        return simplePagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        CommonPagerIndicator indicator = new CommonPagerIndicator(context);
        indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
        indicator.setIndicatorDrawable(mContext.getResources().getDrawable(R.drawable.ic_white_indicator));
        return indicator;
    }
}
